package com.atguigu.spring5.testdemo;

import com.atguigu.spring5.Book;
import com.atguigu.spring5.Orders;
import com.atguigu.spring5.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * IOC入门实例
 */
public class TestSpring5 {

    @Test
    public void testAdd() {
        //1.加载Spring的配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean1.xml");
        //加载spring配置文件的另一种方式，ApplicationContext是BeanFactory的子接口，更灵活，推荐使用
//        BeanFactory beanFactory = new ClassPathXmlApplicationContext("bean1.xml");


        //2.获取配置创建的对象
        User user = applicationContext.getBean("user", User.class);

        System.out.println(user);
        user.add();

    }


    @Test
    public void testBook1() {
        //1.加载Spring的配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean1.xml");
        //加载spring配置文件的另一种方式，ApplicationContext是BeanFactory的子接口，更灵活，推荐使用
//        BeanFactory beanFactory = new ClassPathXmlApplicationContext("bean1.xml");

        //2.获取配置创建的对象
        Book book = applicationContext.getBean("book", Book.class);

        book.testDemo();

    }


    @Test
    public void testOrders() {
        //1.加载Spring的配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean1.xml");

        //2.获取配置创建的对象
        Orders orders = applicationContext.getBean("orders", Orders.class);

        orders.ordersTest();
    }


    @Test
    public void testP() {
        //1.加载Spring的配置文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beanP.xml");

        //2.获取配置创建的对象
        Book book = applicationContext.getBean("book", Book.class);

        book.testDemo();
    }


}
